package pl.lsierant.j2me.bipacz.notifications.impl;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import pl.lsierant.j2me.bipacz.notifications.INotification;
import pl.lsierant.j2me.bipacz.notifications.NotificationType;
import pl.lsierant.j2me.bipacz.persistent.DeserializationHelper;
import pl.lsierant.j2me.bipacz.persistent.IPersistent;
import pl.lsierant.j2me.bipacz.persistent.PersistentObjectType;
import pl.lsierant.j2me.bipacz.persistent.SerializationHelper;

/**
 * Beep notification using specified sound file.
 */
public class BeepNotification implements INotification, IPersistent {
    // sound file name
    private String soundFile;

    /**
     * @param soundFile
     *            sound file name
     */
    public BeepNotification(String soundFile) {
        super();
        this.soundFile = soundFile;
    }

    // used only for persistence
    public BeepNotification() {
    }

    public int getNotificationType() {
        return NotificationType.BEEP;
    }

    public void run() {
        NotificationManager.getInstance().run(this);
    }

    public String getSoundFile() {
        return soundFile;
    }

    public void initialize(DataInputStream serializedData) throws IOException {
        DeserializationHelper helper = new DeserializationHelper(serializedData);
        soundFile = ((String) helper.readObject());
    }

    public void serialize(DataOutputStream out) throws IOException {
        SerializationHelper helper = new SerializationHelper(out, this, 0);
        helper.addField(soundFile);
    }

    public int getPersistentObjectType() {
        return PersistentObjectType.BEEP_NOTIFICATION;
    }

    public String toString() {
        return "BeepNotification [soundFile=" + soundFile + "]";
    }

}
